#! /usr/bin/env python
# -*- coding: utf-8 -*-

# *************************************************************
#     Filename @  mystrip.py
#       Author @  Huoty
#  Create date @  2015-06-08 13:52:26
#  Description @  
# *************************************************************

def mystrip(srcstr):
    '''own strip function'''
    newstr = srcstr
    for i, ch in enumerate(srcstr):
        if ch == ' ':
            newstr = srcstr[i+1:]
        else:
            break

    srcstr = newstr
    rl = range(len(srcstr))
    rl.reverse() # 将序列逆序，没有返回值
    for i in rl:
        if srcstr[i] == ' ':
            newstr = srcstr[:i] # 切片操作是一个前闭后开的集合
        else:
            break

    return newstr

# Script starts from here

if __name__ == "__main__":
    while True:
        srcstr = raw_input('Input a string(input "quit" or "q" exit): \n\t->')
        if srcstr == "quit" or srcstr == "q":
            break
        #elif srcstr == '': # 空字符串，即只回车得到的符
        #    continue
        print "strip result:"
        print "\t[ %s ]" % mystrip(srcstr)

